package com.soft.javase.day06.string;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/24
 */
public class StringDemo1 {
    public static void main(String[] args) {
        // 测试String拼接性能
        long startTime1 = System.currentTimeMillis();
        String str = "";
        for (int i = 0; i < 10000; i++) {
            str += "a"; // 使用+拼接字符串
        }
        long endTime1 = System.currentTimeMillis();
        System.out.println("String拼接耗时: " + (endTime1 - startTime1) + " 毫秒");

        // 测试StringBuilder拼接性能
        long startTime2 = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 10000; i++) {
            sb.append("a"); // 使用StringBuilder拼接
        }
        long endTime2 = System.currentTimeMillis();
        System.out.println("StringBuilder拼接耗时: " + (endTime2 - startTime2) + " 毫秒");
    }
}
